<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>FACE-GARDEN代码生成工具</title>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
</head>
<body id="tag">
	<table border="0" cellspacing="0" cellpadding="0">
		<tbody>
			<tr>
				<td></td>
				<td><h3>FACE-GARDEN代码生成工具</h3></td>
				<td></td>
			</tr>
			<!-- <tr>
				<td></td>
				<td><h4>
						<span style="color: red">暂时只针对MySql数据库<span>
					</h4></td>
				<td></td>
			</tr> -->
		</tbody>
	</table>
	<br>

	<table width="99%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<table width="99%" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td>数据库连接地址:&nbsp;&nbsp;
						<input type="text" name="url" id="url" size="80"
							value="jdbc:mysql://192.168.8.30:3306?useUnicode=true&characterEncoding=UTF-8" /><span
							style="color: red">必填 不需要填写实例名：jdbc:mysql://192.168.0.90:3306?useUnicode=true&characterEncoding=UTF-8&nbsp;,&nbsp;jdbc:oracle:thin:@192.168.090:1521:ora11<span></td>
					</tr>
					<tr>
						<td>数据库连接用户:&nbsp;&nbsp;<input type="text" name="userName" id="userName"
							size="30" value="test" /><span style="color: red">必填<span></td>
					</tr>
					<tr>
						<td>数据库连接密码:&nbsp;&nbsp;<input type="text" name="passWord" id="passWord"
							size="30" value="yGGrHlHEjCWcafQioCnH" /><span style="color: red">必填<span></td>
					</tr>
					<tr>
						<td>数据库连接驱动:&nbsp;&nbsp;<input type="text" name="driverName"
							id="driverName" size="30" value="com.mysql.jdbc.Driver" /><span
							style="color: red">必填,&nbsp;mysql=com.mysql.jdbc.Driver&nbsp;&nbsp;,oracle=oracle.jdbc.driver.OracleDriver<span></td>
					</tr>
					<tr>
						<td>数据库实例名称:&nbsp;&nbsp;<input type="text" name="database" id="database"
							value="dw" size="30" /><span style="color: red">Mysql必填,如果oracle则随便填写<span></td>
					</tr>
					<tr>
						<td>&nbsp;&nbsp;</td>
					</tr>
					<tr>
						<td style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp; <input
							type="button" id="query" value="查询数据库中全部表" />
						</td>
					</tr>
					<tr>
						<td>&nbsp;&nbsp;</td>
					</tr>
					<tr>
						<td>&nbsp;&nbsp;</td>
					</tr>
					<tr>
						<td>项目名称（编码）:&nbsp;&nbsp;<input type="text" name="projectName"
							id="projectName" size="30" value="dw" /><span
							style="color: red">必填 *  com.company.项目名称.manager;<span></td>
					</tr>
					<tr>
						<td>&nbsp;&nbsp;</td>
					</tr>
					<tr>
						<td>公司名称（简称）:&nbsp;&nbsp;<input type="text"
							name="company" id="company" size="30" value="ubox" /><span
							style="color: red">必填 * com.公司名称.projectName.manager;<span></td>
					</tr>
					<tr>
						<td>&nbsp;&nbsp;</td>
					</tr>
					<tr>
						<td>模版名称（编码）:&nbsp;&nbsp;<input type="text" name="module" id="module"
							size="30" value="product"/><span style="color: red">必填<span></td>
					</tr>
					<tr>
						<td>生成输出根目录:&nbsp;&nbsp;D:\work\authcode &nbsp;&nbsp;<input type="hidden" 
							name="outPath" id="outPath" size="30" value="D:\work\authcode" />
							<span style="color: red"><span></td>
					</tr>
					<tr>
						<td>&nbsp;&nbsp;</td>
					</tr>
					<tr>
						<td style="padding-left: 10px;">&nbsp;&nbsp;<input
							type="button" id="generateCode" value="生成分布式代码" />&nbsp;&nbsp;&nbsp;&nbsp;<input
							type="button" id="generateCode1" value="生成基本代码" />&nbsp;&nbsp;&nbsp;&nbsp;<input
							type="button" id="generateCode2" value="生成分布式代码(多数据源)" />&nbsp;&nbsp;&nbsp;&nbsp;<input
							type="button" id="generateCode3" value="微信" /></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td><table width="99%" border="0" cellpadding="0"
					cellspacing="0" style="text-align: center;">
					</td>
					<td>
						<table width="930" height="532" border="0" align=left>
							<tr align="left" height="50" width="300">
								<td colspan="4"><span style="color: red">1、查询表时【项目、公司和模块名称】可以不填写<br />2、但生成代码时必须全部信息完整<span></td>
							</tr>
							<tr align="right" width="136">
								<td colspan="4"><input type="hidden" id="attrGrpId"
									value="" /></td>
							</tr>
							<tr>
								<td>可选数据表</td>
								<td>&nbsp;</td>
								<td align="left">已选数据表</td>
							</tr>
							<tr>

								<td rowspan="2" valign="top" align="right" width="200"
									height="82"><select name="allItem" size="30" id="allItem"
									multiple style="width: 200px;" onclick="onClickAdd();">
								</select></td>
								<td valign="bottom" align="left" width="75" height="82"><button
										type="button" name="addBut" id="addBut" class="normBtn"
										onclick="add();" disabled>
										<span>添加&gt;&gt;</span>
									</button>
									<button type="button" name="removeBut" id="removeBut"
										class="normBtn" onclick="remove();" disabled>
										<span>&lt;&lt;移除</span>
									</button></td>
								<td rowspan="2" align="left" valign="top" width="729"><select
									name="refItem" size="30" id="refItem" multiple
									style="width: 200px;" onclick="onClickRemove();">
								</select></td>
							</tr>
							<tr>
								<td>&nbsp;</td>
								<td align="right" valign="top" width="75" height="310"
									colspan="3"></td>
							</tr>
						</table>
					</td>
					</tr>
				</table> <input type="hidden" id="testQ" />
</body>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$("#query")
								.click(
										function() {
											var url = $("#url").val();
											if (!url) {
												alert("请输入数据库连接地址！");
												return;
											}
											var userName = $("#userName").val();
											if (!userName) {
												alert("请输入数据库连接用户名称！");
												return;
											}
											var passWord = $("#passWord").val();
											var driverName = $("#driverName")
													.val();
											if (!driverName) {
												alert("请输入数据库连接驱动名称！");
												return;
											}
											var database = $("#database").val();
											if (!database) {
												alert("请输入数据库连接实例名称！！");
												return;
											}

											$
													.ajax({
														type : "post",
														url : "queryDataBaseTablesAction",
														dataType : "json",
														data : "&url="
																+ url
																+ "&userName="
																+ userName
																+ "&passWord="
																+ passWord
																+ "&driverName="
																+ driverName
																+ "&database="
																+ database,
														success : function(data) {
															//alert(data.result);
															if (data.result == '1') {
																var rs = data.data;
																var json = eval("("
																		+ rs
																		+ ")");
																// alert(json[0].id);
																for ( var i = 0; i < json.length; i++) {
																	//alert(json[i].id);
																	var $option = $("<option></option>");
																	$option
																			.attr(
																					"value",
																					json[i].id);
																	$option
																			.text(json[i].value);
																	$(
																			"#allItem")
																			.append(
																					$option);
																}

																$("#testQ")
																		.val(
																				"1");
															}
														}
													});

										});
						$("#generateCode3")
						.click(
								function() {
									var testQ = $("#testQ").val();
									if (!testQ || testQ != '1') {
										alert("请先查询到所有数据库表，再选择对应的数据库表生成对应的代码！谢谢");
										return;
									}
									var valIds = "";
									$("#refItem").find('option').each(
											function() {
												valIds = valIds
														+ $(this).val()
														+ ",";
											});
									//    alert("请选择数据库表！"+valIds);
									if ("" == valIds) {
										alert("请选择数据库表！");
										return;
									}
									var url = $("#url").val();
									if (!url) {
										alert("请输入数据库连接地址！");
										return;
									}
									var userName = $("#userName").val();
									if (!userName) {
										alert("请输入数据库连接用户名称！");
										return;
									}
									var passWord = $("#passWord").val();
									var driverName = $("#driverName")
											.val();
									if (!driverName) {
										alert("请输入数据库连接驱动名称！");
										return;
									}
									var database = $("#database").val();
									if (!database) {
										alert("请输入数据库连接实例名称！！");
										return;
									}
									var projectName = $("#projectName")
											.val();
									if (!projectName) {
										alert("请输入項目名称！");
										return;
									}
									var company = $("#company").val();
									if (!company) {
										alert("请输入公司简称！！");
										return;
									}
									var module = $("#module").val();
									if (!module) {
										alert("请输入項目模块名称！！");
										return;
									}
									var outPath = $("#outPath").val();
									$
											.ajax({
												type : "post",
												url : "generateCodeAction",
												dataType : "json",
												data : "&url="
														+ url
														+ "&userName="
														+ userName
														+ "&passWord="
														+ passWord
														+ "&driverName="
														+ driverName
														+ "&database="
														+ database
														+ "&projectName="
														+ projectName
														+ "&module="
														+ module
														+ "&tables="
														+ encodeURI(encodeURI(valIds))
														+ "&outPath="
														+ outPath
														+ "&company="
														+ company+ "&codeType=simple3",
												success : function(data) {
													//alert(data.result);
													if (data.result == '1') {
														alert("代码生成成功！");
													}
												}
											});

								});

						$("#generateCode")
								.click(
										function() {
											var testQ = $("#testQ").val();
											if (!testQ || testQ != '1') {
												alert("请先查询到所有数据库表，再选择对应的数据库表生成对应的代码！谢谢");
												return;
											}
											var valIds = "";
											$("#refItem").find('option').each(
													function() {
														valIds = valIds
																+ $(this).val()
																+ ",";
													});
											//    alert("请选择数据库表！"+valIds);
											if ("" == valIds) {
												alert("请选择数据库表！");
												return;
											}
											var url = $("#url").val();
											if (!url) {
												alert("请输入数据库连接地址！");
												return;
											}
											var userName = $("#userName").val();
											if (!userName) {
												alert("请输入数据库连接用户名称！");
												return;
											}
											var passWord = $("#passWord").val();
											var driverName = $("#driverName")
													.val();
											if (!driverName) {
												alert("请输入数据库连接驱动名称！");
												return;
											}
											var database = $("#database").val();
											if (!database) {
												alert("请输入数据库连接实例名称！！");
												return;
											}
											var projectName = $("#projectName")
													.val();
											if (!projectName) {
												alert("请输入項目名称！");
												return;
											}
											var company = $("#company").val();
											if (!company) {
												alert("请输入公司简称！！");
												return;
											}
											var module = $("#module").val();
											if (!module) {
												alert("请输入項目模块名称！！");
												return;
											}
											var outPath = $("#outPath").val();
											$
													.ajax({
														type : "post",
														url : "generateCodeAction",
														dataType : "json",
														data : "&url="
																+ url
																+ "&userName="
																+ userName
																+ "&passWord="
																+ passWord
																+ "&driverName="
																+ driverName
																+ "&database="
																+ database
																+ "&projectName="
																+ projectName
																+ "&module="
																+ module
																+ "&tables="
																+ encodeURI(encodeURI(valIds))
																+ "&outPath="
																+ outPath
																+ "&company="
																+ company ,
														success : function(data) {
															//alert(data.result);
															if (data.result == '1') {
																alert("代码生成成功！");
															}
														}
													});

										});
						$("#generateCode2")
						.click(
								function() {
									var testQ = $("#testQ").val();
									if (!testQ || testQ != '1') {
										alert("请先查询到所有数据库表，再选择对应的数据库表生成对应的代码！谢谢");
										return;
									}
									var valIds = "";
									$("#refItem").find('option').each(
											function() {
												valIds = valIds
														+ $(this).val()
														+ ",";
											});
									//    alert("请选择数据库表！"+valIds);
									if ("" == valIds) {
										alert("请选择数据库表！");
										return;
									}
									var url = $("#url").val();
									if (!url) {
										alert("请输入数据库连接地址！");
										return;
									}
									var userName = $("#userName").val();
									if (!userName) {
										alert("请输入数据库连接用户名称！");
										return;
									}
									var passWord = $("#passWord").val();
									if (!passWord) {
										alert("请输入数据库连接密码！");
										return;
									}
									var driverName = $("#driverName")
											.val();
									if (!driverName) {
										alert("请输入数据库连接驱动名称！");
										return;
									}
									var database = $("#database").val();
									if (!database) {
										alert("请输入数据库连接实例名称！！");
										return;
									}
									var projectName = $("#projectName")
											.val();
									if (!projectName) {
										alert("请输入項目名称！");
										return;
									}
									var company = $("#company").val();
									if (!company) {
										alert("请输入公司简称！！");
										return;
									}
									var module = $("#module").val();
									if (!module) {
										alert("请输入項目模块名称！！");
										return;
									}
									var outPath = $("#outPath").val();
									$
											.ajax({
												type : "post",
												url : "generateCodeAction",
												dataType : "json",
												data : "&url="
														+ url
														+ "&userName="
														+ userName
														+ "&passWord="
														+ passWord
														+ "&driverName="
														+ driverName
														+ "&database="
														+ database
														+ "&projectName="
														+ projectName
														+ "&module="
														+ module
														+ "&tables="
														+ encodeURI(encodeURI(valIds))
														+ "&outPath="
														+ outPath
														+ "&company="
														+ company
														+ "&codeType=simple2",
												success : function(data) {
													//alert(data.result);
													if (data.result == '1') {
														alert("代码生成成功！");
													}
												}
											});

								});

						$("#generateCode1")
								.click(
										function() {
											var testQ = $("#testQ").val();
											if (!testQ || testQ != '1') {
												alert("请先查询到所有数据库表，再选择对应的数据库表生成对应的代码！谢谢");
												return;
											}
											var valIds = "";
											$("#refItem").find('option').each(
													function() {
														valIds = valIds
																+ $(this).val()
																+ ",";
													});
											//    alert("请选择数据库表！"+valIds);
											if ("" == valIds) {
												alert("请选择数据库表！");
												return;
											}
											var url = $("#url").val();
											if (!url) {
												alert("请输入数据库连接地址！");
												return;
											}
											var userName = $("#userName").val();
											if (!userName) {
												alert("请输入数据库连接用户名称！");
												return;
											}
											var passWord = $("#passWord").val();
											if (!passWord) {
												alert("请输入数据库连接密码！");
												return;
											}
											var driverName = $("#driverName")
													.val();
											if (!driverName) {
												alert("请输入数据库连接驱动名称！");
												return;
											}
											var database = $("#database").val();
											if (!database) {
												alert("请输入数据库连接实例名称！！");
												return;
											}
											var projectName = $("#projectName")
													.val();
											if (!projectName) {
												alert("请输入項目名称！");
												return;
											}
											var company = $("#company").val();
											if (!company) {
												alert("请输入公司简称！！");
												return;
											}
											var module = $("#module").val();
											if (!module) {
												alert("请输入項目模块名称！！");
												return;
											}
											var outPath = $("#outPath").val();
											$
													.ajax({
														type : "post",
														url : "generateCodeAction",
														dataType : "json",
														data : "&url="
																+ url
																+ "&userName="
																+ userName
																+ "&passWord="
																+ passWord
																+ "&driverName="
																+ driverName
																+ "&database="
																+ database
																+ "&projectName="
																+ projectName
																+ "&module="
																+ module
																+ "&tables="
																+ encodeURI(encodeURI(valIds))
																+ "&outPath="
																+ outPath
																+ "&company="
																+ company
																+ "&codeType=simple",
														success : function(data) {
															//alert(data.result);
															if (data.result == '1') {
																alert("代码生成成功！");
															}
														}
													});

										});

					});

	//左右框移动数据
	function add() {
		$("#allItem").find('option:selected').each(
				function() {
					$("#refItem").append(
							"<option value='" + $(this).val() + "'>"
									+ $(this).text() + "</option>");
					$(this).remove();
				});
	}

	//左右框移动数据
	function remove() {
		$("#refItem").find('option:selected').each(
				function() {
					$("#allItem").append(
							"<option value='" + $(this).val() + "'>"
									+ $(this).text() + "</option>");
					$(this).remove();
				});
	}
	//移除按钮不可用
	function onClickAdd() {
		$("#removeBut").attr({
			"disabled" : "disabled"
		});
		$("#addBut").removeAttr("disabled");
	}
	//添加按钮不可用
	function onClickRemove() {
		$("#addBut").attr({
			"disabled" : "disabled"
		});
		$("#removeBut").removeAttr("disabled");
	}
</script>
</html>
